package com.test.tinyurl.util;

import javax.servlet.http.HttpServletRequest;

/**
 * 请求工具类
 */
public class RequestUtil {

    /**
     * 获取当前项目路径
     *
     * @param request
     * @return
     */
    public static String getContextPathUrl(HttpServletRequest request) {

        StringBuffer contextPath = new StringBuffer();

        // 获取协议
        contextPath.append(request.getScheme() + "://");

        // 获取ip
        contextPath.append(request.getServerName() + ":");

        // 获取端口
        contextPath.append(request.getServerPort());

        // 获取项目路径
        contextPath.append(request.getServletContext().getContextPath());
        return contextPath.toString();
    }

}
